package com.candy.databasedocuments.entity;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

/***
 * 表的索引信息
 */
public class TableKeyInfo implements Comparable {

//    public static final String PRIMARY_KEY = "PRIMARY";

    /***
     * 索引名称
     */
    private String name;

    /***
     * 包含那些字段
     */
    private List<String> columns;

    /***
     * 是否唯一
     */
    private Boolean unique;

    /***
     * 索引类型
     */
    private String indexType;

    /***
     * 索引注释
     */
    private String indexComment;

    public TableKeyInfo() {

    }

    public TableKeyInfo(String name, List<String> columns, Boolean unique, String indexType, String indexComment) {
        this.name = name;
        this.columns = columns;
        this.unique = unique;
        this.indexType = indexType;
        this.indexComment = indexComment;
    }

    public String getColumnCombine() {
        return StringUtils.join(columns, ",");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getColumns() {
        return columns;
    }

    public void setColumns(List<String> columns) {
        this.columns = columns;
    }

    public Boolean getUnique() {
        return unique;
    }

    public void setUnique(Boolean unique) {
        this.unique = unique;
    }

    public String getIndexType() {
        return indexType;
    }

    public void setIndexType(String indexType) {
        this.indexType = indexType;
    }

    public String getIndexComment() {
        return indexComment;
    }

    public void setIndexComment(String indexComment) {
        this.indexComment = indexComment;
    }

    @Override
    public int compareTo(Object o) {
        String PRIMARY_KEY = "PRIMARY";
        if (this.equals(o)) {
            return 0;
        }
        TableKeyInfo keyInfo2 = (TableKeyInfo) o;
        String name2 = keyInfo2.getName();
        if (PRIMARY_KEY.equalsIgnoreCase(this.name)) {
            return -1;
        }
        if (PRIMARY_KEY.equalsIgnoreCase(name2)) {
            return 1;
        }
        return this.name.compareTo(name2);
    }

}
